//
//  TwoViewController.swift
//  DemoUI
//
//  Created by 白瑾浩 on 2022/1/8.
//

import UIKit
class TwoViewController: UIViewController {
    var cardId:String?,sex:String?,name:String?
    //定义协议类型的变量
    var delegate:TwoViewControllerProtocol?
    //定义闭包函数
    var closure:((String)->Void)?
    
    
    init?(sex:String,name:String){
        self.name = name
        self.sex = sex
        super.init(nibName: nil, bundle: nil)
    }
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        let button14 = UIButton(type: UIButton.ButtonType.system)
        button14.frame = CGRect(x: 10, y: 200, width: 200, height: 30)
        button14.setTitle("返回", for: UIControl.State.normal)
        button14.addTarget(self, action: #selector(JumpOneViewControl), for: .touchUpInside)
        self.view.addSubview( button14 )
        
        //获取属性值
        let label2 = UILabel(frame: CGRect(x:10,y:250,width: 400,height: 30))
        label2.text = "cardId=\(cardId!),name=\(name!),sex=\(sex!)"
        label2.font = UIFont.boldSystemFont(ofSize:  20 )
        label2.textColor = UIColor.red
        label2.shadowColor = UIColor.green
        label2.shadowOffset = CGSize(width: 10, height:10)
        label2.textAlignment = NSTextAlignment.center
        self.view.addSubview( label2 )
        
        
 let   bgview = UIView(frame: CGRect(x:10,y:300,width: 200,height: 100))
        
        self.view.addSubview( bgview )
        
        let label = UILabel(frame: CGRect(x:0,y:0,width: 200,height: 100))
        label.text  = "我闭包传值给你"
        label.backgroundColor = .blue
        
        
        bgview.addSubview( label )
        
        bgview.setShadow(sColor: UIColor.red, offset: CGSize(width: 0, height: 5), opacity: 0.5, radius: 10)
        
        label.layer.cornerRadius = 10
        label.layer.masksToBounds = true

    }
    @objc func JumpOneViewControl(){
        closure!("我闭包传值给你")
        delegate?.sendData(cardId: cardId!, sex: sex!, name: name!)
        self.dismiss(animated: true, completion: nil)
    }
}

protocol TwoViewControllerProtocol{
    func sendData(cardId:String,sex:String,name:String)
}
extension UIView {
    func setShadow(sColor:UIColor,offset:CGSize,
                       opacity:Float,radius:CGFloat) {
            //设置阴影颜色
            self.layer.shadowColor = sColor.cgColor
            //设置透明度
        self.layer.shadowOpacity = opacity
            //设置阴影半径
        self.layer.shadowRadius = radius
            //设置阴影偏移量
        self.layer.shadowOffset = offset
        }
}

